package com.threefivework.mymall.service.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.threefivework.mymall.exception.MymallException;
import com.threefivework.mymall.model.domain.PaymentRecord;
import com.threefivework.mymall.dao.mapper.PaymentRecordMapper;
import com.threefivework.mymall.service.PaymentRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author yuanshi.fu
 * @description:
 * @date 2018/6/29 下午1:17
 */
@Service
public class PaymentRecordServiceImpl implements PaymentRecordService {

    private static final Logger logger = LoggerFactory.getLogger(PaymentRecordServiceImpl.class);

    @Autowired
    private PaymentRecordMapper paymentRecordMapper;

    @Override
    public List<PaymentRecord> listPaymentRecord() {
        return paymentRecordMapper.list();
    }

    @Override
    public Long insert(PaymentRecord paymentRecord) {
        try {
            Long result = paymentRecordMapper.insert(paymentRecord);
            return paymentRecord.getId();
        } catch (Throwable e) {
            logger.error("[PaymentRecordServiceImpl] insert异常", e);
            throw new MymallException(1, e.getMessage());
        }
    }

    @Override
    public Long batchInsert(List<PaymentRecord> list) {
        try {
            Long result = paymentRecordMapper.batchInsert(list);
            return list.get(0).getId();
        } catch (Throwable e) {
            logger.error("[PaymentRecordServiceImpl] insert异常", e);
            throw new MymallException(1, e.getMessage());
        }
    }

    @Override
    public PaymentRecord getPaymentRecordByPK(Integer id) {
        return paymentRecordMapper.getByPK(id);
    }

    @Override
    public void delete(Integer id) {
        paymentRecordMapper.delete(id);
    }
}
